package com.tanhua.appserver.service;

import com.tanhua.api.UserInfoApi;
import com.tanhua.appserver.interceptor.UserHolder;
import com.tanhua.model.pojo.UserInfo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @Author: JW
 * @Description: TODO
 * @DateTime: 2021/12/21 21:57
 **/

@Service
public class UserInfoService {

    @DubboReference
    private UserInfoApi userInfoApi;

    /**
     * @Author: JW
     * @Description:  TODO 保存用户基本信息
     * @Date: 11:04 2021/12/22
     * @Param: [userInfo]
     * @return: void
    **/
    public void save(UserInfo userInfo) {
        userInfoApi.saveUserInfo(userInfo);
    }

    /**
     * @Author: JW
     * @Description:  TODO 添加用户头像
     * @Date: 11:07 2021/12/22
     * @Param: [url] 头像为存储在阿里云的远程路径
     * @return: void
    **/
    public void addHead(String url) {

        //先在线程空间中拿到用户id
        Long userId = UserHolder.getUserId();

        //查询该用户
        UserInfo userInfo = userInfoApi.findById(userId);

        //将图片路径存储到userInfo中
        userInfo.setAvatar(url);

        //修改用户信息
        userInfoApi.update(userInfo);

    }
}
